package com.lanchetech.user.controller;

import com.lanchetech.bean.request.AnchorRankReq;
import com.lanchetech.bean.request.AnchorWindowsReq;
import com.lanchetech.bean.request.DepositReq;
import com.lanchetech.bean.request.PartnerReq;
import com.lanchetech.bean.response.*;
import com.lanchetech.bean.vo.*;
import com.lanchetech.entity.AnchorWindows;
import com.lanchetech.entity.User;
import com.lanchetech.user.config.ReturnPayInfoVO;
import com.lanchetech.user.service.AnchorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Api(value = "主播接口", tags = "主播接口")
@RequestMapping("/api/anchor")
@RestController
public class AnchorController {

    @Autowired
    AnchorService anchorService;

    @ApiOperation("交纳主播保证金")
    @GetMapping("/createAnchorDeposit")
    public ResultData<ReturnPayInfoVO> createAnchorDeposit(@AuthenticationPrincipal User user, @RequestParam("type") Byte type, @RequestParam("userAddressId") Long userAddressId, HttpServletRequest httpServletRequest) {
        return anchorService.createAnchorDeposit(user, type, userAddressId, httpServletRequest);
    }

    @ApiOperation("是否交纳主播保证金")
    @GetMapping("/paidAnchorDeposit")
    public ResultData<AnchorDepositResp> paidAnchorDeposit(@AuthenticationPrincipal User user) {
        return anchorService.paidAnchorDeposit(user);
    }

    @ApiOperation(value = "购买商品微信支付成功后，处理订单状态【微信支付回调】")
    @RequestMapping(value = "/depositWechatPayNotify", method = {RequestMethod.GET, RequestMethod.POST})
    public String depositWechatPayNotify(@RequestBody String xmlData) {
        return anchorService.depositWechatPayNotify(xmlData);
    }

    @ApiOperation("获取保证金分页")
    @PostMapping("/getAnchorDepositPage")
    public ResultData<BasePageResp<AnchorDepositVO>> getAnchorDepositPage(@RequestBody DepositReq req) {
        return anchorService.getAnchorDepositPage(req);
    }

    @ApiOperation("申请保证金退款")
    @GetMapping("/refundDeposit")
    public BaseResp refundDeposit(@RequestParam("id") Long id) {
        return anchorService.refundDeposit(id);
    }

    @ApiOperation("获取主播个人主页")
    @GetMapping("/getAnchorHome")
    public ResultData<UserInfoVO> getAnchorHome(@RequestParam(value = "userId", required = false) Long userId, @AuthenticationPrincipal User user) {
        return anchorService.getAnchorHome(userId, user);
    }

    @ApiOperation("修改主播个人描述(改为修改小店描述)")
    @GetMapping("/editAnchorDescription")
    public BaseResp editAnchorDescription(@RequestParam("description") String description, @AuthenticationPrincipal User user) {
        return anchorService.editAnchorDescription(description, user);
    }

    @ApiOperation("获取商品橱窗信息")
    @GetMapping("/getProductWindowsData")
    public ResultData<ProductWindowsVO> getProductWindow(@RequestParam("userId") Long userId) {
        return anchorService.getProductWindow(userId);
    }

    @ApiOperation("获取主播排行")
    @PostMapping("/getAnchorRank")
    public ResultData<List<AnchorRankVO>> getAnchorRank(@RequestBody AnchorRankReq req) {
        return anchorService.getAnchorRank(req);
    }

    @ApiOperation("获取当前主播排行")
    @PostMapping("/getCurrentAnchorRank")
    public ResultData<AnchorRankVO> getCurrentAnchorRank(@RequestBody AnchorRankReq req) {
        return anchorService.getCurrentAnchorRank(req);
    }

    @ApiOperation("获取主播橱窗商品分页")
    @PostMapping("/getAnchorWindowsPage")
    public ResultData<BasePageResp<AnchorWindowsVO>> getAnchorWindowsPage(@RequestBody AnchorWindowsReq req, @AuthenticationPrincipal User user) {
        return anchorService.getAnchorWindowsPage(req, user);
    }

    @ApiOperation("编辑主播橱窗(加入橱窗)")
    @PostMapping("/editAnchorWindows")
    public BaseResp editAnchorWindows(@RequestBody AnchorWindows req) {
        return anchorService.editAnchorWindows(req);
    }

    @ApiOperation("删除橱窗商品")
    @GetMapping("/deleteAnchorWindows")
    public BaseResp deleteAnchorWindows(@RequestParam("id") Long id,
                                        @RequestParam("userId") Long userId) {
        return anchorService.deleteAnchorWindows(id,userId);
    }

    @ApiOperation("上下架橱窗商品")
    @GetMapping("/editAnchor")
    public BaseResp editAnchor(@RequestParam("id") Long id, @RequestParam("hidden") Byte hidden) {
        return anchorService.editAnchor(id, hidden);
    }

    @ApiOperation("获取小店分页")
    @PostMapping("/getPartnerPage")
    public ResultData<BasePageResp<PartnerResp>> getPartnerPage(@RequestBody PartnerReq req) {
        return anchorService.getPartnerPage(req);
    }
}
